﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DelonixRegiaHMSys.Core.Interfaces;
using DelonixRegiaHMSys.Core.Models;
using DelonixRegiaHMSys.Infrastructure.Data;
using System.Data.Objects;

namespace DelonixRegiaHMSys.Infrastructure.Data
{
    public class EfHousekeepingQuery : IHousekeepingQuery
    {
        //public IEnumerable<HousekeepingReport> GetAll()
        //{
        //    var context = new hmsDBEntities();
        //    return context.scheduleDetails.Select(f => new HousekeepingReport()
        //    {
        //        ScheduleID = f.scheduleID,
        //        RoomNum = f.roomNum,
        //        StaffID = f.staffID,
        //        ScheduleDateTime = f.scheduledDateTime

        //    });


        //}
        public void AddSchedule(HousekeepingReport sd)
        {
            var context = new hmsDBEntities();
            var newSchedule = context.scheduleDetails.Create();
            newSchedule.scheduleID = sd.ScheduleID;
            newSchedule.roomNum = sd.RoomNum;
            newSchedule.staffID = sd.StaffID;
            newSchedule.scheduledDateTime = sd.ScheduleDateTime;
            context.scheduleDetails.Add(newSchedule);
            context.SaveChanges();
        }

        public void RetrieveSchedule(string scheduleID)
        {
            var context = new hmsDBEntities();
            var scheduleToRetrieve = context.scheduleDetails.FirstOrDefault(s => s.scheduleID == scheduleID);
            context.scheduleDetails.Remove(scheduleToRetrieve);
            context.SaveChanges();
        }

        public void DeleteSchedule(string scheduleID)
        {
            var context = new hmsDBEntities();
            var scheduleToDelete = context.scheduleDetails.FirstOrDefault(s => s.scheduleID == scheduleID);
            context.scheduleDetails.Remove(scheduleToDelete);
            context.SaveChanges();
        }

        public void UpdateSchedule(HousekeepingReport sd)
        {
            var context = new hmsDBEntities();
            var scheduleToUpdate = context.scheduleDetails.FirstOrDefault(s => s.scheduleID == sd.ScheduleID);
            scheduleToUpdate.scheduleID = sd.ScheduleID;
            scheduleToUpdate.roomNum = sd.RoomNum;
            scheduleToUpdate.staffID = sd.StaffID;
            scheduleToUpdate.scheduledDateTime = sd.ScheduleDateTime;

            context.Entry(scheduleToUpdate).State = System.Data.EntityState.Modified;
            context.SaveChanges();

        }
    }
}